#include "Discovery.h"

#include <sstream>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeIterator.h>
#include "misc/Interface.h"
#include "misc/Debug.h"
#include "nameserver/NameServer.h"
#include "nameserver/net/Announce.h"
/*********************************************************/
void Discovery::execute()
{
	Interface& iface = Interface::Instance();
	NameServer& nServer = NameServer::Instance();
	iface << "Received Discovery Message" << std::endl;
	iface.flush();

	std::string addr = nServer.getLocalAddress();

	Announce	ann;
	ann.setAddress(addr);
	
	nServer.broadcast(&ann);
}
/*********************************************************/
std::string Discovery::serialize() const
{
	NameServer& ns = NameServer::Instance();
	std::ostringstream		ostr;
	id = ns.getID();

	ostr << "<GS id='" << id << "'>";
	ostr << "<Discovery></Discovery>";
	ostr << "</GS>";

	return( ostr.str() );
}
/*********************************************************/
void Discovery::deserialize(Poco::XML::NodeIterator& it)
{
	// This messages doesn't carry any specific data so we do nothing here
}
/*********************************************************/
